package it.webrules.deploymanager.core;

import it.webrules.deploymanager.core.config.ConfigurationException;
import it.webrules.deploymanager.core.config.ConfigurationService;
import it.webrules.deploymanager.core.dy.DeployManagerWebapp;
import it.webrules.deploymanager.core.dy.build.CIException;
import it.webrules.deploymanager.core.dy.deploy.AvailableServerException;
import it.webrules.deploymanager.core.dy.deploy.DeployException;
import it.webrules.deploymanager.core.dy.repos.RepositoryException;
import it.webrules.deploymanager.core.st.DeployManagerStatic;
import it.webrules.deploymanager.core.st.scm.SCMException;

import java.util.ArrayList;
import java.util.List;

public class Main {

	private List<Function> functions;

	public Main() {
		functions = new ArrayList<Function>();
		functions.add(new DeployManagerStatic());
		functions.add(new DeployManagerWebapp());
	}

	public Object run(ConfigurationService configurationService) throws ConfigurationException, CIException, RepositoryException,
			AvailableServerException, DeployException, SCMException {

		for (Function function : functions)
			if (function.canManage(configurationService))
				return function.start(configurationService);

		return null;
	}

}
